package com.example.server.util;

import com.example.common.vo.RespBean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class RestTemplateUtils {

    public static <T> RespBean sendPostRequest(RestTemplate restTemplate, T data){
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(
                MediaType.parseMediaType("application/json;charset=utf-8"));
        httpHeaders.add("Accept",MediaType.APPLICATION_JSON.toString());

        HttpEntity<T> httpEntity = new HttpEntity<>(data,httpHeaders);
        ResponseEntity<RespBean> respBeanResponseEntity =
                restTemplate.postForEntity("http://localhost:8083/mail/emp", httpEntity, RespBean.class);
        return respBeanResponseEntity.getBody();
    }
}
